package cn.com.chengq.partters.builder.b02.classpath;

import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;

public class Handler extends URLStreamHandler {
    private static final String key = "java.protocol.handler.pkgs";
    private static String newValue = "cn.com.chengq.partters.builder.b02";

    static {
        if (System.getProperty(key) != null) {
            final String previousValue = System.getProperty(key);
            newValue += "|" + previousValue;
        }
        System.setProperty(key, newValue);
    }

    @Override
    protected URLConnection openConnection(URL u) throws IOException {
        URL resource = ClassLoader.getSystemResource(u.getPath().substring(1));
        return resource != null ? resource.openConnection() : null;
    }

}
